package com.blog.dazi.Controller;

import com.blog.dazi.Service.ChatService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/dazi/chat")
public class ChatController {
    private static final Logger logger = LoggerFactory.getLogger(ChatController.class);

    @Autowired
    private ChatService chatService;

    /**
     * 对话列表
     * @param
     * @param
     * @return
     */
    @GetMapping("/list")
    public List<Map<String,Object>> List(String senderTel,String receiverTel){
        return chatService.findBySenderAndReceiver(senderTel,receiverTel);
    }

    /**
     * 聊天列表 最后聊天的显示在最上端
     * @param tel
     * @return
     */
    @GetMapping("/userList")
    public List<Map<String,Object>> userList(String tel){
        return chatService.userList(tel);
    }

    /**
     * 保存对话
     * @param mes
     * @return
     */
    @PostMapping("/save")
    public int save(@RequestBody String mes){
        return chatService.save(mes);
    }

    /**
     * 显示是否有消息
     * @param type 面板 用户
     * @return
     */
    @GetMapping("/get")
    public Boolean get(String type,String tel){
        return chatService.get(type,tel);
    }



}
